package com.kzj.mls.recyclerCard.cardView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.ab.util.AbViewUtil;
import com.kzj.mls.R;
import com.kzj.mls.recyclerCard.basic.CardItemView;
import com.kzj.mls.recyclerCard.card.TextCard;


public class TextCardView extends CardItemView<TextCard> {

    private Context mContext;
    private TextView textView_button;


    public TextCardView(Context context, AttributeSet attrs,
                        int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
    }

    public TextCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    public TextCardView(Context context) {
        super(context);
        mContext = context;
    }

    @SuppressLint("NewApi")
    @Override
    public void build(final TextCard card) {
        super.build(card);
        textView_button = (TextView) findViewById(R.id.textView_button);
        textView_button.setTag(AbViewUtil.NotScale);
        if (card.getGravity() != -1) {
            card.setGravity(card.getGravity());
        }
        if (card.getHeight() != 0) {
            textView_button.getLayoutParams().height = card.getHeight();
        }
        if (card.getWidth() != 0) {
            textView_button.getLayoutParams().width = card.getWidth();
        }
        if (card.getBackground() != 0) {
            textView_button.setBackgroundResource(card.getBackground());
        }
        if (card.getTextColor() != 0) {
            textView_button.setTextColor(card.getTextColor());
        }
        if (card.getTextSize() != 0) {
            textView_button.setTextSize(TypedValue.COMPLEX_UNIT_PX, card.getTextSize());
        }
        if (card.getOnNormalButtonPressedListener() != null) {
            textView_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    card.getOnNormalButtonPressedListener().onButtonPressedListener(v, card);
                }
            });
        }
        if (card.getText() != null) {
            textView_button.setText(card.getText());
        }
    }
}
